﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Enterprise.Model.Vote;
using Enterprise.Data.Vote;
using Enterprise.Infrastructure;
namespace Enterprise.Service.Vote
{
   public class VoteResultService
    {

        /// <summary>
        /// 用户缓存标记
        /// </summary>
        private static string cacheKey = "Enterprise-VoteResult";

        /// <summary>
        /// 列表 返回所有投票结果
        /// </summary>
        /// <returns></returns>
        public List<VoteResultEntity> VoteResultList()
        {
            if (CacheHelper.Contains(cacheKey))
            {
                return (List<VoteResultEntity>)CacheHelper.GetCache(cacheKey);
            }
            else
            {
                VoteResultData data = new VoteResultData();
                List<VoteResultEntity> list = data.VoteResultList();
                CacheHelper.Add(cacheKey, list);
                return list;
            }
        }

        /// <summary>
        /// 操作 添加、修改、删除
        /// </summary>
        /// <param name="entity">实体</param>
        public void VoteResultExecute(VoteResultEntity entity)
        {
            string cmd = string.Empty;
            switch (entity.DB_Option_Action)
            {
                case "Insert":
                    cmd = "Insert into VOTE_RESULT(VRESULTID,VID,VITEMID,VITEMCODE,VRESULTUSERID,VRESULTTIME) values(SEQ_VOTE_RESULT.nextval,'" + entity.VID + "'," + entity.VITEMID + ",'"+entity.VITEMCODE+"'," + entity.VRESULTUSERID + "," + Utility.FormatOracleDate(entity.VRESULTTIME) + ")";
                    break;
                case "Delete":
                    cmd = "Delete from VOTE_RESULT where VRESULTID='" + entity.VRESULTID;
                    break;
            }
            if (!string.IsNullOrEmpty(cmd))
            {
                VoteResultExecuteBySql(cmd);
            }
        }

        /// <summary>
        /// 操作  
        /// </summary>
        /// <param name="cmd">sql语句</param>
        public void VoteResultExecuteBySql(string cmd)
        {
            VoteResultData data = new VoteResultData();
            data.Execute(cmd);
            CacheHelper.RemoveCache(cacheKey);
        }

    }
}
